package org.tp8.sampleapp.view;

import java.util.LinkedList;
import java.util.List;
import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 * The Class LocaleBean.
 */
@ManagedBean(name = "localeBean")
@SessionScoped
public class LocaleBean extends AbstractBean {

	/** The locale. */
	private Locale locale = FacesContext.getCurrentInstance().getViewRoot()
			.getLocale();

	/**
	 * Gets the locale.
	 * 
	 * @return the locale
	 */
	public Locale getLocale() {
		return locale;
	}

	/**
	 * Gets the language.
	 * 
	 * @return the language
	 */
	public String getLanguage() {
		return locale.getLanguage();
	}

	/**
	 * Sets the language.
	 * 
	 * @param language
	 *            the new language
	 */
	public void setLanguage(String language) {
		locale = new Locale(language);
		FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
	}

	/**
	 * Available locales.
	 * 
	 * @return the list
	 */
	public List<String> availableLocales() {
		List<String> locales = new LinkedList<String>();
		locales.add("en");
		locales.add("el");
		return locales;
	}

}